Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


QUERY-OPEN method

Once you have prepared a query you need to open it, using the QUERY-OPEN method:

hQuery:QUERY-OPEN(). 

The QUERY-PREPARE and QUERY-OPEN methods together accomplish what the OPEN QUERY statement does for a static query. The two methods are separated out to enable you to define the selection and sort criteria for a query separately from opening it. You might want to reopen the same query several times with the same FOR EACH statement, for example, to capture changes to the underlying data the FOR EACH statement retrieves. Having two separate methods gives you this flexibility. It also allows you to verify that the FOR EACH statement in a QUERY-PREPARE is valid before you try to open the query.

You can use the QUERY-PREPARE and QUERY-OPEN methods with static queries as well, even after the query has been opened one or more times with a static OPEN QUERY statement. Here’s an example that extends the static query shown earlier:

DEFINE VARIABLE hQuery    AS HANDLE     NO-UNDO. 
DEFINE VARIABLE cSalesRep AS CHARACTER  NO-UNDO. 
DEFINE QUERY OrderCust FOR Order, Customer.  /* Static definition */ 
hQuery = QUERY OrderCust:HANDLE.        /* Capture the handle */ 
OPEN QUERY OrderCust FOR EACH Order WHERE Order.SalesRep = "BBB", 
    FIRST Customer OF Order.    /* static OPEN */ 
MESSAGE "Static OPEN can't show PREPARE-STRING: "  /* This is UNKNOWN */  
    hQuery:PREPARE-STRING VIEW-AS ALERT-BOX. 
CLOSE QUERY OrderCust. 
/* Code to ask the user for a SalesRep could go here... */ 
cSalesRep = "DKP". 
/* Now use the dynamic methods to re-prepare and re-open the query. */ 
hQuery:QUERY-PREPARE("FOR EACH Order WHERE SalesRep = '" +  
                      cSalesRep + "', FIRST Customer OF Order"). 
hQuery:QUERY-OPEN(). 
MESSAGE "QUERY-PREPARE sets PREPARE-STRING:" SKIP 
    hQuery:PREPARE-STRING VIEW-AS ALERT-BOX. 

The first alert box, shown in Figure 19–5, confirms that you can’t use the PREPARE-STRING attribute on a static OPEN.

Figure 19–5: Static OPEN query message

But the one in Figure 19–6 shows that you can use it when you prepare and open even a static query using the dynamic methods.

Figure 19–6: Dynamic methods with OPEN query message


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095